import  { get,post,patch,put,postFD,del } from './service.js';

//检测用户登录状态
export function userStatus() {
    return new Promise((resolve,reject) => {
        get('/carpool/info/check').then((ret) => {
            resolve(ret)
        }).catch((error) => {
            reject(error)
        })
    })
};


//首页banbar数据
export function bannarData() {
    return new Promise((resolve,reject) => {
        get('/index').then((ret) => {
            resolve(ret)
        }).catch((error) => {
            reject(error)
        })
    })
};

//首页类型数据
export function typeData() {
    return new Promise((resolve,reject) => {
        get('/index/carpool/type').then((ret) => {
            resolve(ret)
        }).catch((error) => {
            reject(error)
        })
    })
};

//首页发布数据
export function homeListData(params) {
    return new Promise((resolve,reject) => {
        get('/index/carpool?carpoolType='+params.carpoolType + '&currentPage='+params.currentPage+'&size='+params.size+'&carpoolInfoId=' + params.carpoolInfoId).then((ret) => {
            resolve(ret)
        }).catch((error) => {
            reject(error)
        })
    })
};

//用户手机号
export function releaseCarpoolingInfo(params) {
    return new Promise((resolve,reject) => {
        postFD('/carpool/info').then((ret) => {
            resolve(ret)
        }).catch((error) => {
            reject(error)
        })
    })
};


//我的模板数据
export function myTemplate(carpoolType) {
    return new Promise((resolve,reject) => {
        get('/carpool/template?carpoolType=' + carpoolType).then((ret) => {
            resolve(ret)
        }).catch((error) => {
            reject(error)
        })
    })
};

//我的发布数据
export function myRelease(carpoolType) {
    return new Promise((resolve,reject) => {
        get('/carpool/info?carpoolType=' + carpoolType).then((ret) => {
            resolve(ret)
        }).catch((error) => {
            reject(error)
        })
    })
};

//删除我的发布
export function deleteMyRelease(id) {
    return new Promise((resolve,reject) => {
        del('/carpool/info/' + id).then((ret) => {
            resolve(ret)
        }).catch((error) => {
            reject(error)
        })
    })
};

//编辑模板
export function setMyTemplate(id,params) {
    return new Promise((resolve,reject) => {
        put('/carpool/template/' + id , params).then((ret) => {
            resolve(ret)
        }).catch((error) => {
            reject(error)
        })
    })
};

//删除模板
export function deleteMyT(id) {
    return new Promise((resolve,reject) => {
        del('/carpool/template/' + id).then((ret) => {
            resolve(ret)
        }).catch((error) => {
            reject(error)
        })
    })
};

//获取客服电话号码接口
export function configPhone() {
    return new Promise((resolve,reject) => {
        get('/system/config/phone').then((ret) => {
            resolve(ret)
        }).catch((error) => {
            reject(error)
        })
    })
};

//获取便民服务信息
export function publicInfoData(params) {
	let url = '/index/contact'
	let arr = Object.keys(params)
	console.log(arr,params)
	arr.map((v,i)=>{
		if(i == 0){
			url=url+`?${v}=${params[v]}`
		}else{
			url=url+`&${v}=${params[v]}`
		}
	})
    return new Promise((resolve,reject) => {
        get(url).then((ret) => {
            resolve(ret)
        }).catch((error) => {
            reject(error)
        })
    })
};

//排行榜
export function userRanks() {
    return new Promise((resolve,reject) => {
        get('/carpool/info/rank').then((ret) => {
            resolve(ret)
        }).catch((error) => {
            reject(error)
        })
    })
};